from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.ext import blobstore

import google.appengine.ext.blobstore


#class Reader():

#     query = 'select __key__ from __BlobInfo__'
#     print query
#     keys =  db.GqlQuery( query )
#     for k in keys:
#       t = db.get(k)
#       print t



class MainPage(webapp.RequestHandler):
    def get(self):
        nl="<br>"

        self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write("reader <br>")

        p = blobstore.BlobInfo.kind()
        print(  p )

        p = blobstore.BlobInfo.properties()
        print(  p )

        blob = blobstore.BlobInfo.all()
        blob = blobstore.BlobInfo.gql("order by creation")


        b = blob[0]      
        blob_key = b.key()
#       r=db.get(blob_key)
#       print( r.filename )

#       print( blob_key.filename )
        print( "opening for read ")

        blob_reader = blobstore.BlobReader(blob_key)

        for line in blob_reader:
             print(line )

application = webapp.WSGIApplication(
                                     [('/reader', MainPage)],
                                     debug=True)


def main():
    run_wsgi_app(application)

if __name__ == "__main__":

#   print __file__
#   print __name__

    main()
